package subumbo.demo.controller {
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	import org.robotlegs.mvcs.Command;
	
	import subumbo.demo.model.WishModel;
	import subumbo.demo.service.WishService;

	public class ShareCommand extends Command {
		
		[Inject] public var wishModel:WishModel;
		[Inject] public var wishService:WishService;
		
		public override function execute():void {
			commandMap.detain(this);
			var data:String = wishModel.wish1 + "," + wishModel.wish2 + "," + wishModel.wish3 + "," + wishModel.wish4 + "," + wishModel.wish5 + "," + wishModel.wish6;
			wishService.setWishes(data);
			wishService.send();
			wishService.result.add(onResult);
		}		
		
		private function onResult(id:String):void {
			
			navigateToURL(new URLRequest("http://facebook.com/sharer.php?u=http://www.subumbo.com/demo/index.html%3Fid=" + id));
			
			commandMap.release(this);
		}
	}
}